<template>
	<view class="mian">
		<uni-nav-bar left-icon="back" status-bar=true fixed=true color="#fff" left-text="返回" right-text="" background-color="#37c0b9"
		 title="登录" @clickLeft="toback"></uni-nav-bar>
		
		<view class="main">
			<view class="title">
				登录/注册
			</view>
			
			<view class="middle">
				<view class="middle-first">
					<input type="number" v-model:value="phone" placeholder="请输入手机号" id="phone"  maxlength="11" style="font-size: 34rpx;" />
					<image src="../../static/imgs/quxiao.png" mode="widthFix"  v-if="isfocus" @input="Focus" ></image>
				</view>
				<view class="middle-second">
					<input type="text" v-model:value="password" placeholder="请输入密码" id="phone" password style="font-size: 34rpx;"/>
					<image src="../../static/imgs/quxiao.png" mode="widthFix" v-if="isfocus" ></image>					
				</view>
				<view class="submit" @click="submit">
				登录
				</view>
				<view class="tips">					
					<view class="register" @click="toRegister">
						立即注册
					</view>
					<view @click="resetpwd">忘记密码</view>
				</view>
			</view>	
		</view>
		
		
	</view>
</template>

<script>
		import api from '@/pages/utils/api.js';
		import compressImage from '@/pages/utils/common.js';
		const device = uni.getSystemInfoSync();
	export default{
		data(){
			return{
				isfocus:false,
				phone:'',
				password:''
			}
		},
		methods:{
			toback:function(){
				uni.navigateBack({
				    delta: 1,
				    animationType: 'pop-out',
				    animationDuration: 200
				});
			},
			Focus(){
				console.log("123")
				this.isfocus=true;
			}, 
			toRegister(){
				uni.navigateTo({
					url:'../register/register'
				})
			},
			
			resetpwd(){
				uni.navigateTo({
					url:'../resetpwd/index'
				})
			},
			
			submit(){
				if(!(/^1[3456789]\d{9}$/.test(this.phone))){ 
					uni.showToast({
						title:"请输入正确手机号",
						icon:"none"
					});return;
				       
				    } 
				if(this.password==''){
					uni.showToast({
						title:"请输入密码",
						icon:"none"
					});return;
					
				}
					let vm =this;
					api.loginApply({
						mobile:vm.phone,
						password:vm.password
					}).then(res=>{
						console.log(res)
						
						if(res.code==-1){
							uni.showToast({
								title:res.msg,
								icon:"none",
								duration:2000,
								})
								return;
							
						}
						uni.setStorageSync("token",res.data.token);
						
						uni.showLoading({
							title: '正在登录...'
						});
						setTimeout(function() {
							uni.hideLoading();
							uni.switchTab({
								url: '/pages/index/index'
							});
						}, 2000);
						
	
						
					})
				}	
			
		}
	}
</script>

<style scoped>
	.main{
		width: 100%;
		margin-top: 150rpx;
	}
	.title{
		padding-left: 45rpx;
		font-size: 60rpx;
		margin: 40rpx 0;
		margin-bottom: 40rpx;
	}
	
	.top-logo{
		width:150rpx;
		height: 150rpx;
		border-radius: 30rpx;
		display: flex;
		justify-content: center;
		align-items: center;
	    background-color: #00a0ea;
		color: #fff;
		}
		.top-logo image{
			width: 100%;
		}
		.middle{
			width: 90%;
			margin: 0 auto;
			
		}
		.middle-first{
			width: 100%;
			height: 80rpx;
			border-bottom: 1px solid #e0e0e0;
			display: flex;
			justify-content: space-between;
		}
		.middle-first image{
			width: 70rpx;
			
		}
		.middle-second{
			width: 100%;
			height: 80rpx;
			border-bottom: 1px solid #e0e0e0;
			margin-top: 50rpx;
			display: flex;
			justify-content: space-between;
		}
		.middle-second image{
			width: 70rpx;
			
		}
		#phone{
			padding-left: 20rpx;
			font-size: 38rpx;
			
			
		}
		.submit{
			display: flex;
			justify-content: center;
			align-items: center;
			width: 100%;
			height: 110rpx;
			background-color: #37c0b9;
			color: #fff;
			margin-top: 80rpx;
			border-radius: 10rpx;
			font-size: 40;
		}
		.tips{
			width:100%;
			margin-top: 20rpx;
			display: flex;
			justify-content: space-between;
			font-size: 34rpx;
			
		}
</style>
